C_OBJS = $(patsubst %.c,%,$(wildcard *.c))
ASM_OBJS = $(patsubst %.S,%, $(wildcard *.S))

# Default values (x=y on command line)
dbg = DEBUG
disp = none
mem = 64M

%: %.S
	@nasm -felf32 $< -o build/$@.o

%: %.c
	@i686-linux-gnu-gcc -D $(dbg) -g -c $< \
			   -o build/$@.o \
			   -Iinclude -ffreestanding \
			   -O0 -Wall -Wextra -Wunused

build: $(C_OBJS) $(ASM_OBJS)
	@i686-linux-gnu-gcc -N -Tlink.ld -g -o build/os.bin -ffreestanding \
		   -O0 -nostdlib build/*.o -lgcc

run: build
	@qemu-system-i386 -serial stdio -kernel build/os.bin -display $(disp) -m $(mem)


clean:
	@rm build/*
